import Mock from "mockjs";
//处理路径传参
import {parameteUrl} from "@/utils/query-param"
import {get_fault_static, get_miles_counts, getFixHistory, getWarning} from "@/mock/home";

function ArrSet(Arr: any[], id: string): any[] {
    let obj: any = {}
    const arrays = Arr.reduce((setArr, item) => {
        obj[item[id]] ? '' : (obj[item[id]] = true && setArr.push(item))
        return setArr
    }, [])
    return arrays
}

/**
 * @description: min ≤ r ≤ max  随机数
 * @param {*} Min
 * @param {*} Max
 * @return {*}
 */
function RandomNumBoth(Min: any, Max: any) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}

export default [
    //左中
    {
        url: "/bigscreen/countUserNum",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    userNumb: 2048,
                    monthIncrease: 52,
                    dayIncrease:6
                }
            })
        },
    },
    // 左上
    {
        url: "/bigscreen/countDeviceNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    totalNum: 38,
                    onlineNum: 38,
                    alarmNum: 3,
                }
            })
            a.data.offlineNum = a.data.totalNum - a.data.onlineNum
            return a
        }
    },
    //左下
    {
        url: "/bigscreen/leftBottom",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    paperNumb: 3571,
                    canNumb: 3862,
                    bottleNumb: 4560
                }
            })
        }
    },
    //右上
    {
        url: "/bigscreen/alarmNum",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: {
                    dateList: ["滨湖区", "梁溪区", "锡山区", "惠山区", "新吴区"],
                    "numList|5": [
                        '@integer(0, 1000)'
                    ],
                    "numList2|5": [
                        '@integer(0, 100)'
                    ]
                }
            })
        }
    },
    //右中
    {
        url: "/bigscreen/ranking",
        type: "get",
        response: () => {
            let dateList= ["滨湖区", "梁溪区", "锡山区", "惠山区", "新吴区","宜兴市","江阴市","吴中区"]
            let arr :any[]=[]
            for(let i=0;i<8;i++){
                arr.push({
                    value:Mock.mock("@integer(50,1000)"),
                    name:dateList[i]
                })
            }
            arr = arr.sort((a: any, b: any) => {
                return b.value - a.value
            })
            return {
                success: true,
                data: arr
            }
        }
    },
    //右下
    {
        url: "/bigscreen/rightBottom",
        type: "get",
        response: () => {
            return Mock.mock({
                success: true,
                data: getFixHistory()
            })
        }
    },
    //中下
    {
        url: "/bigscreen/centerBottom",
        type: "get",
        response: () => {
            return {
                success: true,
                data: get_fault_static()
            }
        }
    },
    {
        url: "/bigscreen/centerMap",
        type: "get",
        response: (options: any) => {
            let params = parameteUrl(options.url)
            //不是中国的时候，代表进入省
            if (params.regionCode && !["china"].includes(params.regionCode)) {
                return Mock.mock({
                    success: true,
                    data: {
                        "dataList|100": [
                            {
                                name: "@city()",
                                value: '@integer(1, 1000)'
                            }
                        ],
                        regionCode: params.regionCode,//-代表中国
                    }
                })
            } else {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|12": [
                            {
                                name: "@province()",
                                value: '@integer(1, 1100)'
                            }
                        ],
                        regionCode: 'china',
                    }
                })
                // 去重
                a.data.dataList = ArrSet(a.data.dataList, "name")
                return a
            }
        }
    }
];

